package com.sg.bars.server.kernel.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.sg.bars.client.kernel.action.Action;

public class ContextActionQueryFactory implements ActionQueryFactory, ApplicationContextAware{
	
	ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

	@Override
	public AbstractActionQuery resolveActionQuery(Action action) {
		AbstractActionQuery actionQuery = (AbstractActionQuery) applicationContext.getBean(action.getActionId());
		actionQuery.setAction(action);
		return actionQuery;
	}

}
